<template>
  <div class="micro-app-container">
    <div class="loading-container" v-if="loading">
      <el-skeleton :rows="10" animated />
    </div>
    <!-- 微应用挂载点使用 App.vue 中的 #subapp-container -->
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, onBeforeUnmount, computed } from 'vue'
import { useRoute } from 'vue-router'
import { useAppStore } from '../store/app'
import { getMicroAppName, getMicroAppTitle } from '../utils/microAppHelper'

const route = useRoute()
const appStore = useAppStore()
const loading = ref(true)

// 获取当前微应用名称
const currentMicroApp = computed(() => {
  return getMicroAppName(route.path)
})

// 获取当前微应用标题
const currentMicroAppTitle = computed(() => {
  return getMicroAppTitle(route.path)
})

onMounted(() => {
  const appName = currentMicroApp.value
  if (appName) {
    appStore.setCurrentMicroApp(appName)
    
    // 模拟加载时间
    setTimeout(() => {
      loading.value = false
    }, 1000)
  }
})

onBeforeUnmount(() => {
  // 离开时清空当前微应用状态
  appStore.setCurrentMicroApp(null)
})
</script>

<style scoped>
.micro-app-container {
  min-height: 500px;
  background-color: #fff;
  border-radius: 4px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  padding: 20px;
}

.loading-container {
  padding: 20px;
}
</style> 